package com.myProject.serves.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myProject.bean.TClass;
import com.myProject.bean.TDisease;
import com.myProject.dao.ClassDao;
import com.myProject.dao.DiseaseDao;
import com.myProject.serves.ClassSev;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionUtil;

import java.util.List;

public class ClassSevImpl implements ClassSev {
    @Override
    public List<TClass> getClassList(TClass tClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassDao cd =  sqlSession.getMapper(ClassDao.class);
        List<TClass>list = cd.getClassList(tClass);
        sqlSession.clearCache();
        return list;
    }

    @Override
    public PageInfo<TClass> showClassByPage(int pageNo, int pageSize, TClass tClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassDao cd =  sqlSession.getMapper(ClassDao.class);
        PageHelper.startPage(pageNo,pageSize);
        List<TClass>list = cd.getClassList(tClass);
        PageInfo<TClass>page = new PageInfo<TClass>(list);
        SqlSessionUtil.commit();
        return page;
    }

    @Override
    public boolean addClass(TClass tClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassDao cd =  sqlSession.getMapper(ClassDao.class);
        int c= cd.addClass(tClass);
        SqlSessionUtil.commit();
//        sqlSession.close();
        return c>0?true:false;
    }

    @Override
    public boolean updateClass(TClass tClass) {
        SqlSession sqlSession = SqlSessionUtil.getSqlSession();
        ClassDao cd =  sqlSession.getMapper(ClassDao.class);
        int x= cd.updateClass(tClass);
        SqlSessionUtil.commit();
        return x>0?true:false;
    }
}
